All files / Bandstand/src/app/api/cues/[id]/image route.ts

0% Statements 0/23
0% Branches 0/1
0% Functions 0/1
0% Lines 0/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                                               
export const dynamic = 'force-dynamic'

import {prisma} from '@/lib/db'
import {requireUser} from '@/lib/guard'
import {route} from '@/lib/route'

/** The picture on one of your cues. */
export const GET = route(
  async (_req: Request, {params}: {params: {id: string}}) => {
    const {user} = await requireUser()
    const img = await prisma.cueImage.findFirst({
      where: {cueId: params.id, cue: {userId: user.id}},
    })
    if (!img) return new Response('Not Found', {status: 404})
    return new Response(new Uint8Array(img.data), {
      headers: {
        'Content-Type': img.mime,
        'Cache-Control': 'private, max-age=31536000, immutable',
        'X-Content-Type-Options': 'nosniff',
      },
    })
  },
)